package com.yztc.love_travel.ui.mainservice.playinlocal.Presenter;

import com.yztc.love_travel.bean.PlayinLocalBean;
import com.yztc.love_travel.ui.mainservice.playinlocal.model.IPlayinLocalModel;
import com.yztc.love_travel.ui.mainservice.playinlocal.model.PlayinLocalModelImpl;
import com.yztc.love_travel.ui.mainservice.playinlocal.view.IPlayinLocalView;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by My on 2016/11/29.
 */

public class PlayinLocalPresenterImpl implements IPlayinLocalPresenter {
    private IPlayinLocalModel mPlayinLocalModel;
    private IPlayinLocalView mPlayinLocalView;

    public PlayinLocalPresenterImpl(IPlayinLocalView mPlayinLocalView) {
        mPlayinLocalModel=new PlayinLocalModelImpl();
        this.mPlayinLocalView = mPlayinLocalView;
    }

    @Override
    public void getPlayinLocalBean(String baseUrl, Map<String, Object> params) {
        mPlayinLocalModel.getPlayinLocalBean(baseUrl,params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<PlayinLocalBean>() {
                    @Override
                    public void onCompleted() {
                        mPlayinLocalView.loadFinish();
                    }

                    @Override
                    public void onError(Throwable e) {
                        mPlayinLocalView.loadError();

                    }

                    @Override
                    public void onNext(PlayinLocalBean playinLocalBean) {
                        mPlayinLocalView.showPlayinLocalData(playinLocalBean);
                    }

                    @Override
                    public void onStart() {
                        super.onStart();
                        mPlayinLocalView.loadStart();
                    }
                });

    }
}
